package com.jack.uikit.expand

import android.graphics.drawable.Drawable
import android.view.View
import com.jack.uikit.view.SelectorBuilder

import com.jack.uikit.view.ShapeBuilder
/**
 * View的扩展属性
 *
 * @author Jack 2021-05-01 16:51
 */
var View.drawable: Drawable
    get() = drawable
    set(value) {
        this.background = value
    }

fun shapeDrawable(bilider: ShapeBuilder.() -> Unit): Drawable {
    return ShapeBuilder().also(bilider).build()
}

fun selectorDrawable(builder: SelectorBuilder.() -> Unit): Drawable {
    return SelectorBuilder().also(builder).build()
}

/**
 * 防止重复点击
 */
fun View.signClick(clickListener: (v: View) -> Unit) {
    isEnabled = false
    postDelayed({
        setOnClickListener {
            clickListener.invoke(it)
        }
        isEnabled = true
    }, 300)
}
